package com.haobangs.imms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.haobangs.imms.mapper.AlarmRecordMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.haobangs.imms.domain.AlarmRecord;
import com.haobangs.imms.service.IAlarmRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报警记录Controller
 *
 * @author haobangss
 * @date 2023-06-29
 */
@RestController
@RequestMapping("/imms/alarmRecord")
public class   AlarmRecordController extends BaseController
{
    @Autowired
    private IAlarmRecordService alarmRecordService;

    @Autowired
    private AlarmRecordMapper alarmRecordMapper;

    /**
     * 分页查询报警记录列表
     */
//    @PreAuthorize("@ss.hasPermi('imms:alarmRecord:list')")
    @GetMapping("/page")
    public Page getByPage(AlarmRecord alarmRecord)
    {
       return alarmRecordService.getByPage(alarmRecord);
    }

    /**
     * 查询报警记录列表
     */
//    @PreAuthorize("@ss.hasPermi('imms:alarmRecord:list')")
    @GetMapping("/list")
    public AjaxResult getAlarRecord(AlarmRecord alarmRecord)
    {
        return AjaxResult.success(alarmRecordMapper.selectList(null));
    }

    /**
     * 导出报警记录列表
     */
//    @PreAuthorize("@ss.hasPermi('imms:alarmRecord:export')")
    @Log(title = "报警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlarmRecord alarmRecord)
    {
        List<AlarmRecord> list = alarmRecordService.selectAlarmRecordList(alarmRecord);
        ExcelUtil<AlarmRecord> util = new ExcelUtil<AlarmRecord>(AlarmRecord.class);
        util.exportExcel(response, list, "报警记录数据");
    }

    /**
     * 获取报警记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('imms:alarmRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(alarmRecordService.selectAlarmRecordById(id));
    }

    /**
     * 新增报警记录
     */
//    @PreAuthorize("@ss.hasPermi('imms:alarmRecord:add')")
    @Log(title = "报警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlarmRecord alarmRecord)
    {
        return toAjax(alarmRecordService.insertAlarmRecord(alarmRecord));
    }

    /**
     * 修改报警记录
     */
//    @PreAuthorize("@ss.hasPermi('imms:alarmRecord:edit')")
    @Log(title = "报警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlarmRecord alarmRecord)
    {
        return toAjax(alarmRecordService.updateAlarmRecord(alarmRecord));
    }

    /**
     * 删除报警记录
     */
//    @PreAuthorize("@ss.hasPermi('imms:alarmRecord:remove')")
    @Log(title = "报警记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(alarmRecordService.deleteAlarmRecordByIds(ids));
    }
}
